{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0b834272",
   "metadata": {},
   "source": [
    "---\n",
    "* 第五周记录\n",
    "* 李锦鹏"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9791a26c",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "## 1.有序的数据结构---列表\n",
    "## 2.用户输入\n",
    "## 3.关于格式化文本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "fc806abb",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_name = \"Marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b75a43fd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Marry,Alex,Jack,Bba\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"Marry,Alex,Jack,Bba\"\n",
    "print(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6a895e57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[6:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "27fa6a99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa710c64",
   "metadata": {},
   "source": [
    "## 引用列表概念\n",
    "#### 1.list可以放数字和字符\n",
    "> 通用的有序数据结构得方法：\n",
    ">> 1.取值：通过索引值取出对应的内容\n",
    ">> 2.切片：通过索引值区间取出对应的一些内容\n",
    ">> 3.in可以查看成员对象是否存在\n",
    "\n",
    "> 列表的一些方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3201fbe1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8fa72fc0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Marry', 'Alex', 'Jack'] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = [\"Marry\",\"Alex\",\"Jack\"]\n",
    "print(网三_name_list,type(网三_name_list))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "844c1d9a",
   "metadata": {},
   "source": [
    "### 列表的运算法则（Operation）\n",
    "* 列表的数据本身不做修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "50da1498",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e467bcfe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7befaea7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三:  Marry\n",
      "网三:  Alex\n",
      "网三:  Jack\n"
     ]
    }
   ],
   "source": [
    "for i in 网三_name_list:\n",
    "    print(\"网三: \",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b29d8ccb",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list_转专业 = [\"ccc\",\"aaa\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e99ae5aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', 'ccc', 'aaa']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list + 网三_name_list_转专业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1eec6b6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "网一_age_list = [\"18\",\"19\",\"20\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8e28e502",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['18', '19', '20']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网一_age_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77b059b4",
   "metadata": {},
   "source": [
    "## 2.2列表得方法（Function）--对列表数据进行操作\n",
    "* 增（append,insert\n",
    "* 删（remove\n",
    "* 改（\n",
    "* 查（"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "64164817",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "1e20845c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# append的使用\n",
    "网三_name_list.append(\"张智豪\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3db2eda7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "357c916b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9beb6eab",
   "metadata": {},
   "outputs": [],
   "source": [
    "# insert的使用\n",
    "网三_name_list.insert(1,\"CT\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "70f95f52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'CT', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "aa420bf1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove的使用\n",
    "网三_name_list.remove(\"CT\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "451d28a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "bbc19314",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b2750e4a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove 经常和 in 一起使用，先检查成员变量是否存在，然后再remove"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "29a815ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if \"CT\" in 网三_name_list:\n",
    "    网三_name_list.remove(\"CT\")\n",
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "a3fc0e45",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张智豪']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "5cca2b8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张智豪'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pop的使用，默认删除倒数第一个\n",
    "网三_name_list.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "57ad73a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "f7cc653a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除19\n",
    "age_list = [18,18,18,18,18,18,18,18,18,19,18,19,18,19,29,29]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "a3e5a289",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "026d66e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 18, 18, 18, 18, 18, 18, 19, 18, 19, 18, 19, 29, 29]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "12cfae9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list.count(19)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3a92640",
   "metadata": {},
   "source": [
    "# 1.删除19\n",
    "a = age_list.count(19)\n",
    "for i in range(a):\n",
    "    if 19 in age_list:\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "39200757",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8 19\n",
      "9 19\n",
      "10 19\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 29, 29]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.删除19\n",
    "for i,v in enumerate(age_list):\n",
    "    if v == 19:\n",
    "        print(i,v)\n",
    "        age_list.pop(i)\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "ed145b1b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n"
     ]
    }
   ],
   "source": [
    "# p68\n",
    "phrase = \"Don't panic\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "33e5cff7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n",
      "Don't panic\n"
     ]
    }
   ],
   "source": [
    "new_phrase = '' .join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7512b70f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n"
     ]
    }
   ],
   "source": [
    "# P81\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e3316b24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dbe5e464",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist[1:3]) \n",
    "new_phrase = new_phrase +''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3b02980d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on tap\n"
     ]
    }
   ],
   "source": [
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7798baf8",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
